import axios from "axios"

// 统计数据
export interface StatisticalData {
    todayOrderCount: number
    todayOrderCountPercentage: number
    todayTotalPrice: number
    todayTotalPricePercentage: number
    todayRegisterUserCount: number
    todayRegisterUserCountPercentage: number
    todayOutStockProductCount: number
    hotProducts: HotProduct[]

    weekDayPrice: number[]
    monthDayPrice: number[]
    yearMonthPrice: number[]
}

export interface HotProduct {
    name: string
    monthlySales: number
}

export function getInitStatisticalData(): StatisticalData {
    return {
        todayOrderCount: 0,
        todayOrderCountPercentage: 0,
        todayTotalPrice: 0,
        todayTotalPricePercentage: 0,
        todayRegisterUserCount: 0,
        todayRegisterUserCountPercentage: 0,
        todayOutStockProductCount: 0,
        hotProducts: [],
        weekDayPrice: [],
        monthDayPrice: [],
        yearMonthPrice: []
    }
}

class HomeApi {

    static baseUrl = '/statistics'

    static async get() {
        try {
            const response = await axios.get("http://localhost:8082" + this.baseUrl)
            return response.data
        }
        catch(error) { throw error }
    }

}

export class StatisticalUtils {
    static get(success: Function) {
        HomeApi.get()
        .then(data => {
            success(data)
        })
    }
}